﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using My.Common.Helper.Utils;
using WarehouseManagement.DataAccess;

namespace WarehouseManagement.BusinessLogic.BC
{
    public class UserBC : BaseBC
    {
        public UserProfile GetUserProfile(string username)
        {
            return Context.UserProfiles.SingleOrDefault(e => e.Username == username);
        }

        public bool Authenticate(string username, string password)
        {
            return Context.UserProfiles.Any(e => e.Username.Equals(username)
                && e.Password.Equals(Hash.CalculateMD5Hash(password)));
        }

        public void ChangePassword(string username, string newPassword)
        {
            var entity = GetUserProfile(username);
            if (entity != null)
            {
                entity.Password = Hash.CalculateMD5Hash(newPassword);
                SubmitChanges();
            }
        }
    }
}
